<?php

class bannersOnRightWidgetComponents extends myComponents{

	public function executeRender(){
		$this->banners = $this->getBanners();

	}



	protected function getBanners(){

		$result = new Doctrine_Collection('Banner');

		$q = Doctrine::getTable('Banner')->createQuery('b')
			->select('b.*')
			->from('Banner b')
			->innerJoin('b.BannerGroup bg')
			->innerJoin('bg.StructureBannerGroups sbg')
			->innerJoin('sbg.Structure s WITH s.id = ?', $this->getRoute()->getObject()->getId())
			->orderBy('b.pri asc')
			->where('bg.type = ?', 'default')
			->limit(4);

		$result = $result->merge($q->execute());

		if($this->getRoute()->getCategoryObject()){
			$q = Doctrine::getTable('Banner')->createQuery('b')
				->select('b.*')
				->from('Banner b')
				->innerJoin('b.BannerGroup bg')
				->innerJoin('bg.BannerGroups sbg')
				->innerJoin('sbg.ProductGroup s WITH s.id = ?', $this->getRoute()->getCategoryObject()->getId())
				->orderBy('b.pri asc')
				->where('bg.type = ?', 'default')
				->limit(4);


			$result = $result->merge($q->execute());
		}

		return $result;		
	}
}
